//
//  NSNumber+ZB.m
//  PaoPao
//
//  Created by xzb on 2018/4/21.
//  Copyright © 2018年 paopao. All rights reserved.
//

#import "NSNumber+ZB.h"

@implementation NSNumber (ZB)

- (NSString *)priceValue
{
    NSString *price;
    if (self.integerValue % 100 != 0) {
        if (self.integerValue % 10 != 0) {
            price = [[NSString alloc] initWithFormat:@"%.2f", self.doubleValue / 100.0];
        } else {
            price = [[NSString alloc] initWithFormat:@"%.1f", self.doubleValue / 100.0];
        }
    } else {
        price = [[NSString alloc] initWithFormat:@"%ld", (long)(self.integerValue / 100)];
    }
    return price;
}

- (NSString *)pointValue
{
    NSString *decimal = @"";
    NSInteger point = self.integerValue % 100;
    if ( point != 0 ) {
        if ( point % 10 != 0) {
            if( point % 100 != 0 && point < 10) {
                decimal = [[NSString alloc] initWithFormat:@".0%ld", (long)point];
            } else {
                decimal = [[NSString alloc] initWithFormat:@".%ld", (long)point];
            }
        } else {
            decimal = [[NSString alloc] initWithFormat:@".%ld", (long)(point / 10)];
        }
    }
    return decimal;
}

- (NSString *)outputPrice
{
    return @(self.floatValue * 100).stringValue;
}

- (NSNumber *)outputPriceNumber
{
    return @(self.floatValue * 100);
}
@end
